package com.wjw.controller.test;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * springboot对象属性注入
 * @ConfigurationProperties用法：https://blog.csdn.net/justry_deng/article/details/90758250
 */
@RestController
@ConfigurationProperties(prefix = "user") //注入对象属性,该对象属性值在application.yml中配置,需要生成属性的set()方法
public class InjectionObjectController {
    private Long id;
    private String username;
    private String password;
    private Double money;
    private Boolean flag;
    private Date birth;
    private String [] arrays;
    private List<String> lists;
    private Map<String,String> maps;

    public void setId(Long id) {
        this.id = id;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setMoney(Double money) {
        this.money = money;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public void setArrays(String[] arrays) {
        this.arrays = arrays;
    }

    public void setLists(List<String> lists) {
        this.lists = lists;
    }

    public void setMaps(Map<String, String> maps) {
        this.maps = maps;
    }

    @GetMapping("/injectObject")
    public String injectObject(){
        System.out.println("id:===>"+id);
        System.out.println("username:===>"+username);
        System.out.println("password:===>"+password);
        System.out.println("money:===>"+money);
        System.out.println("flag:===>"+flag);
        System.out.println("birth:===>"+birth);
        System.out.println("遍历数组===========>");
        for (String s : arrays) {
            System.out.println("s:"+s);
        }
        System.out.println("遍历集合===========>");
        lists.forEach((str)-> System.out.println("str:"+str));
        System.out.println("遍历Map===========>");
        maps.forEach((k,v)-> System.out.println("Key:"+k+",Value:"+v));
        return "injectObject ok";
    }
}
